package Prac;

import java.util.*;

public class P12_5 {

    public int singleNumber(int[] nums) {
        Map<Integer,Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            map.put(nums[i], map.getOrDefault(nums[i],0)+1);
        }
        Set<Map.Entry<Integer,Integer>> set =map.entrySet();
        for (Map.Entry<Integer,Integer> entry: set) {
            if(entry.getValue()==1){
                return entry.getKey();
            }
        }
        return -1;
    }

    public int numJewelsInStones(String jewels, String stones) {
        Set<Character> ch = new HashSet<>();
        int count = 0;
        for (int i = 0; i < jewels.length(); i++) {
            ch.add(jewels.charAt(i));
        }
        for (int i = 0; i < stones.length(); i++) {
            if(ch.contains(stones.charAt(i))){
                count++;
            }
        }
        return count;
    }

    public List<String> topKFrequent(String[] words, int k) {
        Map<String,Integer> map = new HashMap<>();
        for (int i = 0; i < words.length; i++) {
            map.put(words[i], map.getOrDefault(words[i],0)+1);
        }
        Queue<Map.Entry<String,Integer>> queue = new PriorityQueue<>(new Comparator<Map.Entry<String, Integer>>() {
            @Override
            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                return o1.getValue()-o2.getValue()==0?o2.getKey().compareTo(o1.getKey()):o1.getValue()-o2.getValue();
            }
        });

        Set<Map.Entry<String,Integer>> set = map.entrySet();
        for (Map.Entry<String,Integer> entry :set) {
            if(queue.size()<k){
                queue.add(entry);
            }else {
                queue.add(entry);
                queue.poll();
            }
        }
        List<String> ret = new ArrayList<>();
        while (!queue.isEmpty()){
            ret.add(queue.poll().getKey());
        }
        revers(ret);
        return ret;
    }
    public void revers(List<String> ret){
        int left = 0;
        int right = ret.size()-1;
        while (left<right){
            String tmp = ret.get(left);
            ret.set(left,ret.get(right));
            ret.set(right,tmp);
            left++;
            right--;
        }
    }

    public Node copyRandomList(Node head) {
        if(head==null){
            return null;
        }
        Map<Node,Node> map = new HashMap<>();
        Node cur = head;
        while (cur!=null){
            Node node = new Node(cur.val);
            map.put(cur,node);
            cur = cur.next;
        }
        cur = head;
        while (cur!=null){
            map.get(cur).next = map.get(cur.next);//要新节点的next,就通过旧next找,即get(cur.next)
            map.get(cur).random = map.get(cur.random);
            cur = cur.next;
        }
        return map.get(head);
    }



    public boolean containsNearbyDuplicate(int[] nums, int k) {
        Map<Integer,Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if(map.get(nums[i])==null){
                map.put(nums[i],i);
            }else {
                if(Math.abs(map.get(nums[i])-i)<=k){
                    return true;
                }
                map.put(nums[i],i);
            }
        }
        return false;
    }

    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String hope = sc.nextLine();
        String real = sc.nextLine();
        hope = hope.toUpperCase();
        real = real.toUpperCase();
        Set<Character> set = new HashSet<>();
        Set<Character> set2 = new HashSet<>();

        for (int i = 0; i <real.length() ; i++) {
            set.add(real.charAt(i));
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i <hope.length() ; i++) {
            if(!set.contains(hope.charAt(i))&&!set2.contains(hope.charAt(i))){
                set2.add(hope.charAt(i));
                sb.append(hope.charAt(i));
            }
        }
        System.out.print(sb.toString());
    }
}
